# 作者: 宇
# 2025年02月24日21时03分08秒
list1=[1,3,2,4,5,3,2]
print(sorted(list1))#sorted是返回一个有序列表
print(list1)
str_list="This is a test string from Andrew".split()
print(str_list)
print(sorted(str_list))

def str_lower(str1:str):
    return str1.lower()

print(sorted(str_list,key= str_lower))
print("-"*50)
student_tuples=[
    ('john','A',15),
    ('jane','B',12),
    ('dave','B',10)
]
print(sorted(student_tuples,key=lambda x:x[2]))

class Student:
    def __init__(self,name,grade,age):
        self.name=name
        self.grade=grade
        self.age=age

    def __repr__(self):
        return  repr((self.name,self.grade,self.age))
Student_object=[
    Student('John','A',15),
    Student('Jane','B',12),
    Student('dave','B',10)
]
from  operator import itemgetter,attrgetter
print(sorted(Student_object,key=lambda student:student.age))
print(sorted(student_tuples,key=itemgetter(0,2),reverse=True))

mydict = { 'Li' : ['M',7],
    'Zhang': ['E',2],
    'Wang' : ['P',3],
     'Du' : ['C',2],
     'Ma' : ['C',9],
     'Zhe' : ['H',7] }
print(sorted(mydict.items(),key=lambda v:v[0]))
gameresult = [
{ "name":"Bob", "wins":10, "losses":3, "rating":75.00 },
{ "name":"David", "wins":3, "losses":5, "rating":57.00 },
{ "name":"Carol", "wins":4, "losses":5, "rating":57.00 },
{ "name":"Patty", "wins":9, "losses":3, "rating": 71.48 }]
print(sorted(gameresult,key=itemgetter("rating","name")))
tuples = [(3,5),(1,2),(2,4),(3,1),(1,3)]
print(sorted(tuples, key=lambda x: (x[0], -x[1])))


